package com.smforj.ssm.modules.lib.service.impl;

import com.smforj.ssm.frame.core.enums.JDataSource;
import com.smforj.ssm.modules.lib.dao.InventoryBooksDao;
import com.smforj.ssm.modules.lib.dao.MissionDao;
import com.smforj.ssm.modules.lib.domain.trolley.InventoryBook;
import com.smforj.ssm.modules.lib.domain.trolley.MissionBook;
import com.smforj.ssm.modules.lib.domain.trolley.MissionRequest;
import com.smforj.ssm.modules.lib.domain.trolley.MissionResponse;
import com.smforj.ssm.modules.lib.service.MissionService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author jadeshi
 * @date 2017/11/28 16:06
 * @name MissionServiceImpl.java
 * @package com.smforj.ssm.sys.domain.trolley
 **/
@Service
@JDataSource("sstation")
public class MissionServiceImpl implements MissionService {

    /**
     * 获取任务图书Service
     */
    @Autowired
    private MissionDao missionDao;
    @Autowired
    private InventoryBooksDao inventoryBooksDao;


    @Override
    public List<MissionBook> getMission(MissionRequest missionRequest) {
        List<MissionBook> bookList = missionDao.getMissionBook(missionRequest.getSzUserId(), missionRequest.getNowTime());
        return bookList;
    }

    @Override
    public List<MissionResponse> insertBooks(List<MissionBook> missionBooks) {
        List<MissionResponse> responseList = new ArrayList<MissionResponse>();
        MissionResponse missionResponse = null;
        for (MissionBook book : missionBooks
                ) {
            missionResponse = new MissionResponse();
            InventoryBook inventoryBook = new InventoryBook();
            inventoryBook.setMissionId(book.getMissionId());
            inventoryBook.setRfid(book.getRfid());
            inventoryBook.setMissionId(book.getMissionId());
            inventoryBook.setBookname(book.getBookname());
            inventoryBook.setResult(book.getRemark());
            inventoryBooksDao.insert(inventoryBook);
//            missionResponse.setBarcode(inventoryBook.getBarcode());
            responseList.add(missionResponse);
        }
        return responseList;
    }


}
